#include "CelestialBody.h"
#include "Math.h"


CCelestialBody::CCelestialBody(int x, int y, CIw2DImage* img, CCelestialBody* center, int r, int R, double period):CDrawable(x,y,img) {
	timer = 0;
	parent = center;
	this->r=r;
	this->R=R;
	this->period = period;
	timer = x*1000+y*100;
}
CCelestialBody::CCelestialBody(int x, int y, CIw2DImage* img):CDrawable(x,y,img) {
	timer = 0;
	parent = NULL;
}


CCelestialBody::~CCelestialBody(void) { 
}
int CCelestialBody::GetX() {
// 	if (image) {
// 		return CDrawable::GetX()+image->GetWidth()/2;
// 	}
	return CDrawable::GetX();
}
int CCelestialBody::GetY() {
// 	if (image) {
// 		return CDrawable::GetY()+image->GetHeight()/2;
// 	}
	return CDrawable::GetY();
}
void CCelestialBody::Update(unsigned int deltaTime) {
	timer += deltaTime;
	if(parent!=NULL) {
		double alngle = (timer*2*3.14/1000) / period;
		x = (int)(parent->GetX() + R*sin(alngle));
		y = (int)(parent->GetY() + r*cos(alngle));
	}

}
void CCelestialBody::Render() {
	if(parent!=NULL) {
		Iw2DSetColour(0xff444444);//orbit color
		Iw2DDrawArc(CIwSVec2(parent->GetX(),parent->GetY()),CIwSVec2(R,r),IW_FIXED(0),IW_FIXED(3.14),100);
	}
	CDrawable::Render();
}